package wang.Demo;

import java.util.Random;
import java.util.Scanner;

public class ShuangSeQiuDemo9 {
    public static void main(String[] args) {
        //实现双色球
        int[] usernumbers = userSlectNumbers();
        int[] Luckeynumbers = LuckyNumbers();
        System.out.println("您选择的双色球号码为");
        print(usernumbers);
        System.out.println("中奖号码为");
        print(Luckeynumbers);
        Biggo(usernumbers,Luckeynumbers);
    }
    //1.设计一个方法，让用户选择号码
    public static int[] userSlectNumbers(){
        int[] numbers = new int[7];
        int number;
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < numbers.length - 1; i++) {
            //输入前6个红球号码，号码在1-33之间且不能重复
            while (true) {
                System.out.println("请您输入第" + (i+1)+"个红球号码");
                number = sc.nextInt();
                if (number<1 || number>33){
                    System.out.println("对不起您输入的范围有误请重新输入");
                }
                if (exit(numbers,number)){
                    System.out.println("您输入的号码重复请重新输入 ");
                }else{
                    numbers[i]=number;
                    break;
                }
            }
        }
        while (true) {
            System.out.println("请您输入最后一个蓝球号码");
            number = sc.nextInt();
            if (number<1 || number>16){
                System.out.println("您输入的号码有误请重新输入 ");
            }else {
                numbers[6] = number;
                break;
            }
        }
        return numbers;
    }

    //设计方法，产生随机中奖号码
    public static int[] LuckyNumbers(){
        int[] numbers = new int[7];
        int number=0;
        Random data = new Random();
            for (int i = 0; i < numbers.length - 1; i++) {
                while (true) {
                    number = data.nextInt(33)+1;
                    if (exit(numbers,number)){

                    }else {
                        numbers[i] = number;
                        break;
                    }
                }
            }
        numbers[6]= data.nextInt(16)+1;
            return numbers;
    }
    //设计方法，判断用户是否中奖
   public static void Biggo(int[] usernumber, int[] Luckynumber){
        int redcount = 0;
        int bluecount = 0;
       for (int i = 0; i < Luckynumber.length-1; i++) {
           for (int j = 0; j < usernumber.length-1; j++) {
               if (Luckynumber[i] == usernumber[j]){
                   redcount++;
                   break;
               }
                   bluecount=Luckynumber[6] == usernumber[6] ? 1:0;

           }
       }
       if (redcount==6 && bluecount == 1){
           System.out.println("恭喜您中奖1000万元");
       }else if (redcount == 6 && bluecount ==0){
           System.out.println("恭喜您中奖500万元");
       }else if (redcount == 5 && bluecount ==1){
           System.out.println("恭喜您中奖1000元");
   }else if (redcount == 5 && bluecount ==0 ||redcount == 4 && bluecount == 1){
           System.out.println("恭喜您中奖500元");
       }else if (redcount == 4 && bluecount ==0 ||redcount == 3 && bluecount == 1){
           System.out.println("恭喜您中奖20元");
       }else if (redcount <3 && bluecount == 1){
           System.out.println("恭喜您中奖5元");
       }else {
           System.out.println("抱歉您没有中奖");
       }
   }
    //检测用户输入的号码是否重复
    public static boolean exit(int[] a , int number){
        for (int i = 0; i < a.length - 1; i++) {
            if(number == a[i]){
                return true;
            }
        }
            return false;
    }
    //打印数组内的号码
    public static void print(int[] b){
        System.out.print("[");
        for (int i = 0; i < b.length; i++) {
            System.out.print(i == b.length-1 ? b[i]:b[i]+" ");
        }
        System.out.println("]");
    }
}
